package IOperation;

import Book.Book;
import Book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * User: wenxiwen
 * Date: 2022/4/15
 * Time: 10:47
 * Description: No Description
 */
public class Del implements IOperation{
    public void work(BookList bookList) {
        System.out.println("删除图书");

        System.out.println("请输入要删除的书名：");
        Scanner scan = new Scanner(System.in);
        String name = scan.nextLine();
        int dex = bookList.getCount();
        int i = 0;
        int index = 0;
        for (i = 0; i < dex; i++) {
            Book book = bookList.getBook(i);
            if(book.getName().equals(name)) {
                index = i;
                break;
            }
        }
        for (int j = index; j < dex-1; j++) {
            bookList.setBooks(j,bookList.getBook(j+1));
        }

        bookList.setCount(dex-1);
        bookList.setBooks(dex-1,null);
        System.out.println("删除成功！");

    }
}